package com.hex.ds.hdtp.core.inf.script.common.service.impl;

import com.hex.ds.hdtp.core.inf.script.common.service.IScriptConvertService;
import com.hex.hdtp.scf.basic.convert.entity.ConvertConfig;
import com.hex.hdtp.scf.basic.convert.entity.ConvertResult;
import com.hex.hdtp.scf.basic.convert.service.ScriptConversionService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author gj.xu
 * @Date 2023/12/1
 */
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScriptConvertService implements IScriptConvertService {

    private final Map<String, ScriptConversionService> convertServiceMap;


    /**
     * @Method scriptConvert
     * @Param
     * @Param convertType
     * @Param convertConfig
     * @Return com.hex.hdtp.scf.basic.convert.entity.ConvertResult
     * @Description 获取 SCF 对应 SPI 并转换
     * @Author gj.xu
     * @Date 2023/12/1 13:44
     * @Version V2.0
     */
    @Override
    public ConvertResult scriptConvert(String convertType, ConvertConfig convertConfig) {
        return convertServiceMap.get(convertType).convert(convertConfig);
    }


    /**
     * @Method scriptAnalyze
     * @Param
     * @Param convertType
     * @Param convertConfig
     * @Return com.hex.hdtp.scf.basic.convert.entity.ConvertResult
     * @Description 获取 SCF 对应 SPI 并分析
     * @Author gj.xu
     * @Date 2023/12/7 11:03
     * @Version V2.0
     */
    @Override
    public ConvertResult scriptAnalyze(String convertType, ConvertConfig convertConfig) {
        return convertServiceMap.get(convertType).analyze(convertConfig);
    }

    /**
     * @Method scriptConvertType
     * @Param
     * @Return java.util.List<java.lang.String>
     * @Description 获取脚本 SCF 插件类型
     * @Author gj.xu
     * @Date 2023/12/1 13:30
     * @Version V2.0
     */
    @Override
    public List<String> scriptConvertType() {
        return new ArrayList<>(convertServiceMap.keySet());
    }
}
